/**
 * @Author：ming
 * @Date：2023/10/2 8:38 PM
 * @Filename：Hj5
 */

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * @author ming
 */
public class Hj5 {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        String str;
        while ((str=br.readLine())!=null){
            str = str.substring(2);
            int sum = 0;
            int len = str.length();

            for (int i = len-1; i >= 0; i--) {
                char c= str.charAt(i);
                int temp=0;
                if(c>='A'&&c<='F'){
                    temp = c-55;
                }else if(c>='0'&&c<='9'){
                    temp = c-48;
                }
                int current =temp*(int) Math.pow(16,len-i-1);
                sum += current;
            }
            System.out.println(sum);

        }
    }
}
